/*
 * Rectangle.h
 *
 *  Created on: 2012/07/04
 *      Author: weihe
 */

#ifndef RECTANGLE_H_
#define RECTANGLE_H_

#include "Point2.h"

namespace geom {

class Rectangle {
public:
	float x, y, width, height;
	Rectangle(float width = 0, float height = 0, float x = 0, float y = 0) :
			x(x), y(y), width(width), height(height) {
	}

	void reset(float width = 0, float height = 0, float x = 0, float y = 0) {
		this->width = width;
		this->height = height;
		this->x = x;
		this->y = y;
	}

	float aspect() {
		return width / height;
	}

	float min() {
		return width < height ? width : height;
	}

	float left() {
		return x;
	}
	void left(float v) {
		x = v;
	}

	float right() {
		return x + width;
	}
	void right(float v) {
		width = v - x;
	}

	float top() {
		return y;
	}

	void top(float v) {
		y = v;
	}

	float bottom() {
		return y + height;
	}
	void bottom(float v) {
		height = v - y;
	}

	Point2f center() {
		return Point2f(x + width / 2, y + height / 2);
	}

	void center(Point2f v) {
		x = v.x - width / 2;
		y = v.y - height / 2;
	}

	void createInside(Rectangle outter, float aspect);

};

} /* namespace geom */
#endif /* RECTANGLE_H_ */
